home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / LList Mgr / LList Mgr For Think C / LList.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-22  |  16.9 KB  |  444 lines  |  [TEXT/KAHL]

  1. /************************************************************/
  2. /*                                                            */
  3. /* LList.h                                                    */
  4. /*                                                            */
  5. /* Version 1.4, May 1994, added ignoreCase to LLSearch,        */
  6. /*                          added drawNow to LLDoDraw,        */
  7. /*                          added LLSort function                */
  8. /* Version 1.3, April 1994, fixed bug w/no scroll bar,        */
  9. /*                            LLDoDraw(theList, 1) no longer     */
  10. /*                            auto-redraws the list so call     */
  11. /*                            LLUpdate if necessary            */
  12. /* Version 1.2, December 1993, added column frame option,    */
  13. /*                               condenses type if needed,    */
  14. /*                               added LLRect function,        */
  15. /*                               fixed LLAddRow redraw bug    */
  16. /* Version 1.1, November 1993, fixed thumb scrolling bug    */
  17. /* Version 1.0, September 1993                                */
  18. /* Tad Woods, T&T Software, 70312,3552 on CompuServe        */
  19. /*                                                            */
  20. /* LList is an alternative list manager to the standard        */
  21. /* toolbox list manager. The advantages of LList are the    */
  22. /* abilities to have variable width    columns, a different     */
  23. /* text style for each column, and lists larger than 32K.    */
  24. /* Unlike the standard list manager, LList only    scrolls        */
  25. /* vertically, requires a fixed number of columns to        */
  26. /* be set when the list is created via LLNew, and entire    */
  27. /* rows, not individual cells, can be highlighted.            */
  28. /* LList has about the same performance and the function    */
  29. /* calls are similar to the toolbox list manager.            */
  30. /* LLists may be unlimited total size, but individual        */
  31. /* cells may not contain data bigger than 32K. Currently     */
  32. /* LList is totally pointer based.                            */
  33. /*                                                            */
  34. /* LList has been tested and used but comes with no            */
  35. /* guarantees. You may include LList with your own            */
  36. /* compiled code. You may not sell or distribute LList        */
  37. /* source code without permission of T&T Software.            */
  38. /* Send comments or problem reports to the address above.    */
  39. /*                                                            */
  40. /************************************************************/
  41.  
  42. #pragma once
  43.  
  44. enum {                        // Values for selFlags
  45.     LLOnlyOne = -128,        // only one cell can be selected at a time
  46.     LLExtendDrag = 64,        // drag extends without shift key down
  47.     LLNoDisjoint = 32,        // click deselects all previous selections
  48.     LLNoExtend = 16,        // shift won't extend selection
  49.     LLUseSense = 4,            // shift senses state of initial cell
  50.     LLNoNilHilite = 2        // don't highlight empty rows
  51. };
  52.  
  53.  
  54. typedef struct {            // Description of how to draw a column
  55.     short        width;        // width in pixels, default is list width div by number of cols
  56.     short        style;        // TextFace values, default is plain
  57.     short        justify;    // 0=left justify in cell (default), 1=center, -1=right
  58.     short        dodraw;        // 1=draw column (default), 0=don't draw column
  59.     short        highlight;    // 1=highlight column (default), 0=don't highlight column
  60.     short        frame;        // 0x0008 frame left, 0x0004 right, 0x0002 top, 0x0001 bottom, 0x000F all
  61. } LColDesc;
  62.  
  63.  
  64. typedef struct {            // Column data
  65.     Ptr            data;
  66.     short        dataLen;
  67. } LCol;
  68.  
  69.  
  70. typedef struct {            // Row data
  71.     void        *nextRow;
  72.     void        *prevRow;
  73.     short        needDraw;
  74.     short        selected;
  75.     LCol        col[];        // array[0..numOfColumns] of column data records
  76. } LRow;
  77.  
  78.  
  79. typedef struct {
  80.     Rect            view;        // display rectangle in local coords
  81.     WindowPtr        window;        // window where list resides
  82.     ControlHandle    scroll;        // ControlRecord for scroll bar
  83.     short            font;        // list font
  84.     short            size;        // list font size
  85.     short            height;        // list line height in pixels
  86.     short            baseline;    // pixels from bottom of text to bottom of row
  87.     short            indent;        // pixels to indent from edge of column
  88.     short            dodraw;
  89.     char            selFlags;    // determines how selection is performed with mouse
  90.     char            activeFlag;
  91.     LRow            *row;        // pointer to first LRow
  92.     LRow            *lastClkRow;    // pointer to last row clicked in
  93.     long            lastClkTime;
  94.     short            numOfRows;        // number of rows in list
  95.     short            firstVisRowNum;    // number of first visible row in list
  96.     short            numOfVisRows;    // number of visible rows in view Rect
  97.     short            numOfColumns;    // number of columns in list
  98.     long            refCon;        // for your use
  99.     LColDesc        colDesc[];    // array[0..numOfColumns] of column description records
  100. } LList;
  101.  
  102.  
  103. /************************************************************/
  104. /*                                                            */
  105. /* LLActivate                                                */
  106. /*                                                            */
  107. /*  -> theList        pointer to LList                        */
  108. /*  -> activate        1=activate, 0=deactivate                */
  109. /*                                                            */
  110. /* Activates or deactivates a LList. Call after an            */
  111. /* activate event.                                            */
  112. /*                                                            */
  113. /************************************************************/
  114. pascal void LLActivate(LList *theList, short activate);
  115.  
  116.  
  117. /************************************************************/
  118. /*                                                            */
  119. /* LLAddRow            returns pointer to new row or NULL        */
  120. /*                    (returns NULL if there's not enough     */
  121. /*                    memory)                                    */
  122. /*                                                            */
  123. /*  -> theList        pointer to LList                        */
  124. /*  -> beforeRow    pointer to row that new row will come    */
  125. /*                    before                                    */
  126. /*                                                            */
  127. /* Adds a new row to a LList. If beforeRow = NULL a row        */
  128. /* will be added to the end of the list.                    */
  129. /*                                                            */
  130. /************************************************************/
  131. pascal LRow *LLAddRow(LList *theList, LRow *beforeRow);
  132.  
  133.  
  134. /************************************************************/
  135. /*                                                            */
  136. /* LLClick            returns 1 if user double-clicks in list    */
  137. /*                    otherwise returns 0                        */
  138. /*                                                            */
  139. /*  -> theList        pointer to LList                        */
  140. /*  -> localPoint    click location in local coordinates        */
  141. /*  -> modifiers    shift, cmd, etc. from event record        */
  142. /*                                                            */
  143. /* Processes mouse-down for list dragging and selection.    */
  144. /* Call LLClick when a mousedown event occurs inside the    */
  145. /* list view area of a window. LLClick performs row         */
  146. /* selection according to criteria established by the        */
  147. /* bits of LList.selFlags.                                    */
  148. /*                                                            */
  149. /************************************************************/
  150. pascal short LLClick(LList *theList, Point localPoint, short modifiers);
  151.  
  152.  
  153. /************************************************************/
  154. /*                                                            */
  155. /* LLDelRow                                                    */
  156. /*                                                            */
  157. /*  -> theList        pointer to LList                        */
  158. /*  -> row            pointer to list row, or NULL to delete    */
  159. /*                    all rows                                */
  160. /*                                                            */
  161. /* Deletes the row and releases all of its associated         */
  162. /* memory.                                                    */
  163. /*                                                            */
  164. /************************************************************/
  165. pascal void LLDelRow(LList *theList, LRow *row);
  166.  
  167.  
  168. /************************************************************/
  169. /*                                                            */
  170. /* LLDispose                                                */
  171. /*                                                            */
  172. /*  -> theList        pointer to LList                        */
  173. /*                                                            */
  174. /* Dispose of a LList and release all of its memory.        */
  175. /*                                                            */
  176. /************************************************************/
  177. pascal void LLDispose(LList *theList);
  178.  
  179.  
  180. /************************************************************/
  181. /*                                                            */
  182. /* LLDoDraw                                                    */
  183. /*                                                            */
  184. /*  -> theList        pointer to LList                        */
  185. /*  -> dodraw        1=changes to LList are displayed as     */
  186. /*                    they occur, 0=list will not be updated    */
  187. /*                    until drawing is turned back on            */
  188. /*  -> drawNow        1=draw list items that need drawing        */
  189. /*                    immediately, 0=do not draw now (call    */
  190. /*                    LLUpdate to force the list to redraw).    */
  191. /*                    Note: drawNow is ignored if dodraw = 0.    */
  192. /*                                                            */
  193. /* Turns list drawing normally performed by other LList     */
  194. /* Manager functions on or off.                                */
  195. /*                                                            */
  196. /************************************************************/
  197. pascal void LLDoDraw(LList *theList, short dodraw, short drawNow);
  198.  
  199.  
  200. /************************************************************/
  201. /*                                                            */
  202. /* LLGetCell                                                */
  203. /*                                                            */
  204. /*  -> theList        pointer to LList                        */
  205. /*  -> row            pointer to list row                        */
  206. /*  -> colNum        column number of cell in row            */
  207. /*                    (column numbers start at 0)                */
  208. /* <-> dataLen        on entry size in bytes of buffer at        */
  209. /*                    data, on return actual length of data    */
  210. /*                    transferred                                */
  211. /*  -> data            pointer to buffer, on return this         */
  212. /*                    buffer contains the data from the cell    */
  213. /*                                                            */
  214. /* Get a copy of a cell's data.                                */
  215. /*                                                            */
  216. /************************************************************/
  217. pascal void LLGetCell(LList *theList, LRow *row, short colNum, short *dataLen, Ptr data);
  218.  
  219.  
  220. /************************************************************/
  221. /*                                                            */
  222. /* LLGetSelect        returns 1 if a selected row is             */
  223. /*                    found, 0 if not                            */
  224. /*                                                            */
  225. /*  -> theList        pointer to LList                        */
  226. /* <-> row            pointer to list row    pointer                */
  227. /*                    on entry pointer to a row to test        */
  228. /*                    first, on return pointer to a selected    */
  229. /*                    row if a selected row was found            */
  230. /*  -> advanceit    0=examine one row, 1=keep looking        */
  231. /*                                                            */
  232. /* Queries if a row is selected; gets the next selected        */
  233. /* row if advanceit = 1. Note that in searching for all        */
  234. /* selections in a list, you will need to advance row        */
  235. /* (use LLNextRow) after a selection is found.                */
  236. /*                                                            */
  237. /************************************************************/
  238. pascal short LLGetSelect(LList *theList, LRow **row, short advanceit);
  239.  
  240.  
  241. /************************************************************/
  242. /*                                                            */
  243. /* LLNew            returns a pointer to a new LList        */
  244. /*                    (returns NULL if there's not enough     */
  245. /*                    memory)                                    */
  246. /*                                                            */
  247. /*  -> view            pointer to list display    rectangle in    */
  248. /*                    local coordinates                        */
  249. /*  -> window        pointer to window where list resides    */
  250. /*  -> rowHeight    height of a row in pixels                */
  251. /*                    (if you change LList.height after the    */
  252. /*                    LLNew call you also need to recalcualte    */
  253. /*                    LList.numOfVisRows)                        */
  254. /*  -> numOfColumns    number of columns in the list            */
  255. /*                    (5 columns would be numbered 0 thru 4)    */
  256. /*  -> hasScroll    1=list has vertical scroll bar, 0=no    */
  257. /*                    scroll bar                                */
  258. /*  -> selFlags        determines how selection of rows is     */
  259. /*                    processed in LLClick calls                */
  260. /*                    See Values for selFlags above.            */
  261. /*                                                            */
  262. /* Allocates and initializes a LList record.                */
  263. /*                                                            */
  264. /************************************************************/
  265. pascal LList *LLNew(Rect *view, WindowPtr window, short rowHeight, short numOfColumns, short hasScroll, short selFlags);
  266.  
  267.  
  268. /************************************************************/
  269. /*                                                            */
  270. /* LLNextRow        returns a pointer to next row            */
  271. /*                    returns NULL if no next row                */
  272. /*                                                            */
  273. /*  -> theList        pointer to LList                        */
  274. /*  -> row            pointer to a row                        */
  275. /*                                                            */
  276. /* Returns a pointer to the row after row. Pass NULL for    */
  277. /* row and LLNextRow will return a pointer to the first        */
  278. /* row in the list.                                            */
  279. /*                                                            */
  280. /************************************************************/
  281. pascal LRow *LLNextRow(LList *theList, LRow *row);
  282.  
  283.  
  284. /************************************************************/
  285. /*                                                            */
  286. /* LLPrevRow        returns a pointer to previous row        */
  287. /*                    returns NULL if no previous row            */
  288. /*                                                            */
  289. /*  -> theList        pointer to LList                        */
  290. /*  -> row            pointer to a row                        */
  291. /*                                                            */
  292. /* Returns a pointer to the row before row. Pass NULL for    */
  293. /* row and LLPrevRow will return a pointer to the last        */
  294. /* row in the list.                                            */
  295. /*                                                            */
  296. /************************************************************/
  297. pascal LRow *LLPrevRow(LList *theList, LRow *row);
  298.  
  299.  
  300. /************************************************************/
  301. /*                                                            */
  302. /* LLRect                                                    */
  303. /*                                                            */
  304. /*  -> theList        pointer to LList                        */
  305. /*  -> row            pointer to a row                        */
  306. /*  -> colFirst        first column to contain rectangle        */
  307. /*  -> colLast        last column to contain rectangle        */
  308. /* <-  theRect        local coordindates of rectangle that    */
  309. /*                    encloses the specified row and columns    */
  310. /*                                                            */
  311. /* Obtains the local coordinates of the rectangle that        */
  312. /* encloses the specified row and column(s).                */
  313. /*                                                            */
  314. /************************************************************/
  315. pascal void LLRect(LList *theList, LRow *row, short colFirst, short colLast, Rect *theRect);
  316.  
  317.  
  318. /************************************************************/
  319. /*                                                            */
  320. /* LLScroll                                                    */
  321. /*                                                            */
  322. /*  -> theList        pointer to LList                        */
  323. /*  -> rows            <0 scroll list down specific number of    */
  324. /*                    rows, >0 scroll list up specific         */
  325. /*                    number of rows                            */
  326. /*                                                            */
  327. /* Scrolls the list a specific number of rows relative        */
  328. /* to the current displayed rows.                            */
  329. /*                                                            */
  330. /************************************************************/
  331. pascal void LLScroll(LList *theList, short rows);
  332.  
  333.  
  334. /************************************************************/
  335. /*                                                            */
  336. /* LLScrollToRow                                            */
  337. /*                                                            */
  338. /*  -> theList        pointer to LList                        */
  339. /*  -> row            pointer to a row                        */
  340. /*                                                            */
  341. /* Scrolls the list so that row is the first row displayed.    */
  342. /* If row is NULL the list scrolls to the bottom.            */
  343. /*                                                            */
  344. /************************************************************/
  345. pascal void LLScrollToRow(LList *theList, LRow *row);
  346.  
  347.  
  348. /************************************************************/
  349. /*                                                            */
  350. /* LLSearch            returns 1 if data is found, 0 if not    */
  351. /*                                                            */
  352. /*  -> theList        pointer to LList                        */
  353. /* <-> row            pointer to pointer to list row            */
  354. /*                    on entry row to start search at or NULL    */
  355. /*                    to start search at first row, on return    */
  356. /*                    row where data was found if found        */
  357. /* <-  colFound        on return pointer to column number of    */
  358. /*                    row where data was found, if found        */
  359. /*  -> colFirst        colFirst and colLast define the range    */
  360. /*  -> colLast        of columns to search in                    */
  361. /*  -> data            pointer to buffer containing data to    */
  362. /*                    search for                                */
  363. /*  -> dataLen        length of buffer                        */
  364. /*  -> ignoreCase    1 = comparison is case-insensitive,        */
  365. /*                    0 = comparison is case-sensitive        */
  366. /*                                                            */
  367. /* Searches all columns of all rows beginning at *row         */
  368. /* for data.                                                */
  369. /*                                                            */
  370. /************************************************************/
  371. pascal short LLSearch(LList *theList, LRow **row, short *colFound, short colFirst, short colLast, Ptr data, short dataLen, short ignoreCase);
  372.  
  373.  
  374. /************************************************************/
  375. /*                                                            */
  376. /* LLSetCell                                                */
  377. /*                                                            */
  378. /*  -> theList        pointer to LList                        */
  379. /*  -> row            pointer to list row                        */
  380. /*  -> colNum        column number of cell in row that will     */
  381. /*                    receive data (col. nums. start at 0)    */
  382. /*  -> dataLen        length of buffer                        */
  383. /*  -> data            pointer to buffer containing data to    */
  384. /*                    be placed in the cell                    */
  385. /*                                                            */
  386. /* Stores a copy of data into a cell.                        */
  387. /* (If there's not enough memory to copy data into this        */
  388. /* cell, the cell will be empty.)                            */
  389. /*                                                            */
  390. /************************************************************/
  391. pascal void LLSetCell(LList *theList, LRow *row, short colNum, short dataLen, Ptr data);
  392.  
  393.  
  394. /************************************************************/
  395. /*                                                            */
  396. /* LLSetSelect                                                */
  397. /*                                                            */
  398. /*  -> theList        pointer to LList                        */
  399. /*  -> row            pointer to list row    to select or        */
  400. /*                    deselect                                */
  401. /*  -> setit        1=select, 0=deselect                    */
  402. /*                                                            */
  403. /* Selects or deselects a cell.                                */
  404. /*                                                            */
  405. /************************************************************/
  406. pascal void LLSetSelect(LList *theList, LRow *row, short setit);
  407.  
  408.  
  409. /************************************************************/
  410. /*                                                            */
  411. /* LLSort                                                    */
  412. /*                                                            */
  413. /*  -> theList        pointer to LList                        */
  414. /*  -> col1            sort by data field of this column        */
  415. /*                    number                                    */
  416. /*  -> col2            sort rows with the same col1 by data    */
  417. /*                    field of this column number, or -1 for    */
  418. /*                    no second or third sort field            */
  419. /*  -> col3            sort rows with the same col2 by data    */
  420. /*                    field of this column number, or -1 for    */
  421. /*                    no third sort field                        */
  422. /*  -> ignoreCase    1 = comparison is case-insensitive,        */
  423. /*                    0 = comparison is case-sensitive        */
  424. /*  -> order        1 = sort order is ascending,            */
  425. /*                    -1 = sort order is descending            */
  426. /*                                                            */
  427. /* Sorts and re-draws a list (using a simple bubble-sort).     */
  428. /*                                                            */
  429. /************************************************************/
  430. pascal void LLSort(LList *theList, short col1, short col2, short col3, short ignoreCase, short order);
  431.  
  432.  
  433. /************************************************************/
  434. /*                                                            */
  435. /* LLUpdate                                                    */
  436. /*                                                            */
  437. /*  -> theList        pointer to LList                        */
  438. /*                                                            */
  439. /* Redraws the list. Call LLUpdate in response to an update    */
  440. /* event in the list's window.                                */
  441. /*                                                            */
  442. /************************************************************/
  443. pascal void LLUpdate(LList *theList);
  444.